import n from "./AudioManager"
import l from "./EventMgr"
import s from "./MatchGameEventType"
import c from "./frameworkManager"
import u from "./SdkHelper"
import p from "./MatchGameData"
import d, { AnimType } from "./BasePageCtrl"
import h from "./MatchGameSystemMgr"
import f from "./UiManage"
import g from "./MatchGameSetPage"
import BasePageCtrl from "./BasePageCtrl"
import UiManager from "./UiManage"
import AdManager from "./AdManager"
import NativeUtils from "./NativeUtils"

const { ccclass, property } = cc._decorator;

@ccclass
export default class MatchGameSetPageCtrl extends BasePageCtrl {
    ui = null;
    public clickStartGame = !1;
    public _animType = AnimType.NONE;
    public _touchControl = false;
    public _hasPeneLock = true;
    public _hasBlack = true;
    public _hasTouchLock = false;
    public _hasBlackTouch = false;

    onLoad() {
        this.onUILoad();
        this._animType = AnimType.NONE;
        this._touchControl = !1;
        this._hasPeneLock = !0;
        this._hasBlack = !0;
        this._hasTouchLock = !1;
        this._hasBlackTouch = !1;
        super.onLoad();
        this.addButtonListen();
    };
    start() { };
    onUILoad() {
        this.ui = this.node.addComponent(g);
    };
    addButtonListen() {
        UiManager.addButtonListen(this.ui.btn_close, this.clickClose, this);
        UiManager.addButtonListen(this.ui.btn_leave, this.leaveCallback, this);
        UiManager.addButtonListen(this.ui.btn_restart, this.restartCallback, this);
        UiManager.addButtonListen(this.ui.btn_goon, this.goonCallback, this);
        UiManager.addButtonListen(this.ui.btn_music, this.musicTouch, this);
        UiManager.addButtonListen(this.ui.btn_sound, this.audioTouch, this);
        UiManager.addButtonListen(this.ui.btn_shock, this.shakeTouch, this);
    };
    _init() {
        this.refreshView();
    };

    public _onShow(): void {
        super._onShow();
        NativeUtils.showScreenAds(8, () => { }, true)
    }

    public hide(): void {
        super.hide();
        NativeUtils.showScreenAds(8, () => { }, false)
    }

    refreshView() {
        this.changeSwitchState(this.ui.music_on, n.getInstance().getMusicState());
        this.changeSwitchState(this.ui.sound_on, n.getInstance().getAudioState());
        this.changeSwitchState(this.ui.shock_on, n.getInstance().getVibratorState());
        this.clickStartGame = !1;
    };
    musicTouch() {
        if (n.getInstance().getMusicState()) {
            n.getInstance().closeBg();
            n.getInstance().pauseMusic("bgm", !0);
            n.getInstance().pauseMusic("bgm_outSide", !0);
        } else {
            n.getInstance().openBg();
            n.getInstance().playMusic("bgm", !0, !0);
        }
        this.changeSwitchState(this.ui.music_on, n.getInstance().getMusicState());
    };
    audioTouch() {
        n.getInstance().getAudioState() ? n.getInstance().closeAudio() : n.getInstance().openAudio();
        this.changeSwitchState(this.ui.sound_on, n.getInstance().getAudioState());
    };
    shakeTouch() {
        var e = n.getInstance().getVibratorState();
        e ? n.getInstance().closeVibrator() : n.getInstance().openVibrator();
        this.changeSwitchState(this.ui.shock_on, !e);
    };
    changeSwitchState(e, t) {
        e.active = t;
    };
    goonCallback() {
        NativeUtils.report2("level_setting", {
            level_id: p.gameLevel,
            setting_continue: 1,
            setting_restart: 0,
            setting_exit: 0,
        });
        this.hide();
    };
    leaveCallback() {
        NativeUtils.report2("level_setting", {
            level_id: p.gameLevel,
            setting_continue: 0,
            setting_restart: 0,
            setting_exit: 1,
        });
        l.trigger(s.END_MATCH_GAME, {
            is_tg: 0
        });
        this.hide();
    };
    restartCallback() {
        var e = this;
        c.log("restartCallback,", this.clickStartGame);
        if (!this.clickStartGame) {
            this.clickStartGame = !0;
            NativeUtils.report2("level_setting", {
                level_id: p.gameLevel,
                setting_continue: 0,
                setting_restart: 1,
                setting_exit: 0,
            });
            h.matchGameStart(null, function () {
                var t = p.getGameInfo();
                c.log("MatchGameData.getGameInfo", t);
                l.trigger(s.LOAD_MATCH_SCENE, !0);
                e.hide();
            }, function () {
                e.hide();
            });
        }
    };
    clickClose() {
        this.hide();
    };
}
